HA$PBExportHeader$u_cst_noconforme_msj.sru
forward
global type u_cst_noconforme_msj from u_cst_manto_main
end type
end forward

global type u_cst_noconforme_msj from u_cst_manto_main
integer width = 3863
event type boolean ue_grabar_error ( )
end type
global u_cst_noconforme_msj u_cst_noconforme_msj

type variables
userobject iuo_object
end variables

event type boolean ue_grabar_error();long  ll_idosac
string ls_users,ls_ordenes,ls_orden_temp,ls_userscopia
integer li_cadena,li_fila,li_orden,li_ini,li_osac
ll_idosac = dw_1.object.data [1,1]
ls_users =dw_1.object.iduserreceptores[1] //idusers
ls_userscopia =dw_1.object.tuserscopia[1] //copia_user
li_orden = dw_1.object.idorden[1]  //idorden
li_osac = integer( istr_parm.string_parm[3])

//copia al user hchavez(user admin de mensajes)
If sqlca.Usp_Add_OSAC(ll_idosac,ls_users,'M','E') <> 0 then 
	RollBack;
	Return  FALSE
End if		

update mosac set bstat= 'F' , ttipo = 'S'   where idosac = :li_osac;

select idosac into  :ll_idosac from mosac where idOrden = :li_orden and bOrigen = 1 and tTipo = 'O' ;

//no conforme
If sqlca.Usp_Add_OSAC(ll_idosac,ls_users,'X','E') <> 0 then 
	RollBack;
	Return  FALSE
End if		

return TRUE
end event

on u_cst_noconforme_msj.create
int iCurrent
call super::create
end on

on u_cst_noconforme_msj.destroy
call super::destroy
end on

event ue_ver_default;boolean lb_sw
//if ab_ver = true then lb_sw = false
//if ab_ver = false then lb_sw = true

dw_1.enabled= false

dw_1.visible = false
dw_2.visible = false
uo_1.visible = true
uo_toolbarstrip.visible = false
st_titulo.visible = true
st_det1.visible = true
uo_toolbarstrip.of_setvisible( 'Enviar', false)
uo_toolbarstrip.of_setvisible( 'Cancelar', false)
uo_toolbarstrip.of_setvisible( 'Editar', false)
uo_toolbarstrip.of_setvisible( 'Borrar', false)
uo_toolbarstrip.of_setenabled( 'Enviar', false)		
uo_toolbarstrip.of_setenabled( 'Cancelar', false)
end event

event ue_ver_object;boolean lb_sw
if ab_ver = true then lb_sw = false
if ab_ver = false then lb_sw = true

dw_1.enabled= ab_ver
dw_2.enabled = ab_ver

uo_toolbarstrip.visible = true
uo_toolbarstrip.of_setvisible( 'Enviar', ab_ver)
uo_toolbarstrip.of_setvisible( 'Cancelar', ab_ver)
//uo_toolbarstrip.of_setvisible( 'Editar', lb_sw)
uo_toolbarstrip.of_setvisible( 'Borrar', lb_sw)
uo_toolbarstrip.of_setenabled( 'Enviar', ab_ver)		
uo_toolbarstrip.of_setenabled( 'Cancelar', ab_ver)

dw_1.visible = ab_ver
dw_2.visible = lb_sw
//iuo_grillamain.event dynamic ue_dw_enabled(true,ll_Rows
end event

event ue_nuevo;LONG ll_movimiento,ll_ticket
string ls_tele
is_button = 'Nuevo'
dw_1.reset()
dw_1.insertrow(0)

dw_1.object.data[1,1] = of_getcodigo()
ll_movimiento =0
//sqlca.Usp_GetIdTablaINT('ORDEN_OSAC',ll_movimiento)
dw_1.object.idOrden[1] = integer(istr_parm.string_parm[1])
ll_ticket = long(istr_parm.string_parm[1])
dw_1.object.iduser[1] = gs_iduser
dw_1.setcolumn('tmsj'); dw_2.setfocus()
dw_1.object.tosac [1] =   istr_parm.string_parm[1]
dw_1.object.fproceso [1] =  today()
//dw_1.object.tusersCopia [1] = 'hchavez'
dw_1.object.tasunto [1] ='No conforme'

dw_1.object.iduserreceptores [1]= istr_parm.string_parm[2]

select top 1 tnrotelefono into :ls_tele from mosac where idorden = :ll_ticket and ttipo = 'O';
dw_1.object.tnrotelefono [1]=ls_tele


end event

event ue_grabar_previo;call super::ue_grabar_previo;LONG ll_movimiento
ll_movimiento =0
dw_1.object.data[1,1] = of_getcodigo()
//sqlca.Usp_GetIdTablaINT('ORDEN_OSAC',ll_movimiento)
//dw_1.object.idOrden[1] = 0 //ll_movimiento
end event

event ue_setdwc;dw_2.GetChild("idtipomaq", dwc);dwc.reset();			dwc.settransobject( sqlca);			dwc.retrieve( )		
end event

event ue_grabar;integer li_return=1,li_fila,li_orden,li_existe
string ls_empresa,ls_asunto,ls_msj

if dw_1.accepttext( ) =  - 1  then return 0
If f_findrequired(dw_1) = -1 Then Return 0
ls_asunto = dw_1.object.tasunto[1]
ls_msj = dw_1.object.tmsj[1]
li_orden = dw_1.object.idorden[1]

select count(*) into :li_existe from mosac where idorden = :li_orden and ttipomsj = 'X' ;
if li_existe > 0  then
	f_msj('El ticket ya fue reenviado por la no conformidad, por favor verifique...',4); return 0 
end if

if isnull(ls_msj) or len(ls_msj) = 0 or trim(ls_msj)='' then
	f_msj('Debe ingresar el mensaje',1); return 0 
end if



EVENT UE_GRABAR_PREVIO()
dw_1.object.fproceso [1] =  today()
if trim(ls_asunto)='' or isnull(ls_asunto) then
	 dw_1.object.tasunto[1]='SIN ASUNTO'
end if
dw_1.object.idOrden[1] = integer(istr_parm.string_parm[1])

 dw_1.object.ttipo[1]='S'
 dw_1.object.iduserreceptor[1]=gs_iduser
if dw_1.update(true,false) = 1 then
	if This.Event ue_Grabar_Error() then
//		dw_2.reset(); dw_2.clear()
		//dw_1.RowsCopy(dw_1.GetRow(),dw_1.GetRow(), primary!, dw_2, 1, Primary!)
		dw_1.resetupdate();	commit;
		//iuo_grillamain.event dynamic ue_refrescar_row(dw_2,ii_row,is_button)
	//	f_msj('Guardado satisfactoriamente',4)
		iuo_object.EVENT DYNAMIC ue_refrescar()
		//iuo_grillamain.event ue_activa_opc( false)
		//event ue_ver_object(false)
		//event ue_settabtext( 'Consultar')
		return 1
		
	else
		rollback ; f_msj('Error',1);	return 0
	end if
	
else
	//dw_1.resetupdate()
	rollback ;	f_msj('Error',1) ;	return 0
end if
return 0

//if dw_1.update(true,false) = 1 then
//	//NO HUBO ERROR AL GRABAR
//	if This.Event ue_Grabar_Error(false) then
//		MessageBox('Informaci$$HEX1$$f300$$ENDHEX$$n','El Proceso de Grabaci$$HEX1$$f300$$ENDHEX$$n se Realizo Exitosamente',information!)
//		this.event post ue_Grabar_Pos()
//		return 1
//	end if
//	
//else
//	//ERROR EN GRABAR
//	this.Event ue_Grabar_Error(TRUE) 
//end if
//
return 0
end event

event constructor;string ls_dw3,ls_dw2,ls_opc,ls_dw,ls_user
long ll_codigo

istr_parm = message.powerobjectparm 

//uo_toolbarstrip.visible = false
//dw_1.visible = false
of_getwindow()

ids_datastore   = istr_parm.ads_menu //aqui recupera el datastore
uo_powerdock = istr_parm.auo_powerdock 
is_button         = istr_parm.as_button
ls_dw              = ids_datastore.object.tDw1[1]
is_tabla           ='MOSAC'// ids_datastore.object.tTabla[1]
IF ISNULL(is_tabla) THEN is_tabla =''

is_entidad = ids_datastore.object.tEntidad[1]
iuo_tab            = istr_parm.auo_userobject 
 iuo_object  =istr_parm.auo_userobject

iuo_tabmantomain = istr_parm.auo_tabmantomain
//is_idcodigo			=  istr_parm.as_parm[1] //id tabla
//if ls_dw = '' or isnull(ls_dw) then return

//dw_1.dataobject=ls_dw
//dw_2.dataobject=ls_dw
dw_1.settransobject(sqlca)
dw_2.settransobject(sqlca)
dw_2.retrieve()
commit;

event ue_nuevo( )
//uo_1.of_BackColor2(of_GetColor("BACKGROUND2"))
uo_1.of_BackColor2(RGB(129,169,226))
//event post ue_settabtext ('')
//EVENT ue_mostrar (istr_parm,true,0)



end event

event resize;uo_toolbarstrip.Width =newWidth
//(this.width - 12) 

//Dw_1.Resize(newWidth - Dw_2.Width , newHeight  )
Dw_1.Resize(newWidth,newHeight)

//DW_2.Resize(newWidth - Dw_1.Width , newHeight   )
//DW_2.move( Dw_1.Width  ,DW_2.y)

uo_1.Resize(newWidth, newHeight)
end event

type st_msj from u_cst_manto_main`st_msj within u_cst_noconforme_msj
end type

type st_det2 from u_cst_manto_main`st_det2 within u_cst_noconforme_msj
boolean visible = false
integer x = 329
integer y = 1788
end type

type st_det1 from u_cst_manto_main`st_det1 within u_cst_noconforme_msj
boolean visible = false
integer x = 288
integer y = 1916
end type

type st_titulo from u_cst_manto_main`st_titulo within u_cst_noconforme_msj
boolean visible = false
integer x = 306
integer y = 1664
end type

type dw_2 from u_cst_manto_main`dw_2 within u_cst_noconforme_msj
integer x = 3090
integer y = 1780
integer width = 768
integer height = 324
string dataobject = "d_muser_msj"
end type

event dw_2::itemchanged;call super::itemchanged;string ls_dest
integer li_i, li_cont = 0
choose case getcolumnname()
	case 'ok'
		accepttext()
	
		dw_1.object.tuserscopia[dw_1.getrow()] = ''
		for li_i = 1 to dw_2.rowcount()
			if dw_2.object.ok[li_i] = 1 and li_i <> getrow() then
				li_cont = li_cont + 1
				if li_cont = 1 then
	
					dw_1.object.tuserscopia[dw_1.getrow()] = string(dw_2.object.iduser[li_i])
				else
	
					dw_1.object.tuserscopia[dw_1.getrow()] = dw_1.object.tuserscopia[dw_1.getrow()]+','+string(dw_2.object.iduser[li_i]	)
				end if
			end if
		next
		if dw_2.object.ok[getrow()] = 0 then
			ls_dest = dw_1.object.tuserscopia[dw_1.getrow()]
			if len(ls_dest) <= 0 then 
	
				dw_1.object.tuserscopia[dw_1.getrow()] = string(dw_2.object.iduser[getrow()])
				
			else
	
				dw_1.object.tuserscopia[dw_1.getrow()] = dw_1.object.tuserscopia[dw_1.getrow()]+','+string(dw_2.object.iduser[getrow()])

			end if
		end if
end choose
end event

type uo_toolbarstrip from u_cst_manto_main`uo_toolbarstrip within u_cst_noconforme_msj
boolean visible = true
integer width = 3858
end type

event uo_toolbarstrip::constructor;this.of_AddItem('Enviar', 'Insert!')
this.of_AddItem('Cancelar', 'Undo!')
//this.of_AddItem('Editar', '..\IMG\ICO\edit.ico')
//this.of_AddItem('Borrar', '..\IMG\ICO\Delete.ico')

//opciones en estado invisible
this.of_setvisible( 'Enviar', true)
this.of_setvisible( 'Cancelar', true)
//esto es para mostar los textos
this.of_DisplayText(true)


end event

event uo_toolbarstrip::ue_buttonclicked;string ls_columna,ls_tipo,ls_codigo
integer li_codigo
long ll_codigo
choose case upper(as_button)
	
	case 'EDITAR'
		
		   is_button  =	as_button
		   iuo_tabmantomain.event dynamic ue_setbutton(as_button)
		   iuo_tabmantomain.event	dynamic ue_set_ib_sw(true)
//		   is_idcodigo =dw_2.object.data[1,1]
		   iuo_grillamain.event dynamic ue_activa_opc( true)
		   event ue_settabtext ('Editar '+ is_entidad)
		   event ue_ver_object(true)
		   ls_columna = dw_1.describe('#'+string(1)+'.name')
		   ls_tipo = dw_1.describe(ls_columna+'.coltype')	
			if left(ls_tipo,4)='char' then
				 ls_codigo =dw_2.object.data[1,1]
				 of_retrieve( ls_codigo)	
			elseif ls_tipo='int' then
				 li_codigo =dw_2.object.data[1,1]
				 of_retrieve( li_codigo)	
			else
				ll_codigo =dw_2.object.data[1,1]
				 of_retrieve( ll_codigo)	
			end if		

	case 'ENVIAR'
		if event  ue_grabar( ) = 1  then
			uo_powerdock.of_closedocument(uo_powerdock.of_getactiveobject( ) )
		else
			return
		end if
		
	case 'CANCELAR'
		if dw_1.modifiedcount( ) > 0  then
			if f_msj('$$HEX1$$bf00$$ENDHEX$$Esta seguro que desea cancelar?',2)  = 2  then return
		end if
		
		uo_powerdock.of_closedocument(uo_powerdock.of_getactiveobject( ) )
		
		
//		if	event ue_getdwmodified( ) > 0 then
//			if f_msg('Cambio realizados ... $$HEX1$$bf00$$ENDHEX$$Esta seguro que desea cancelar ?',7) = 2 then return
//	
//		end if
//		IF UPPER(is_button) = 'EDITAR' Then
//			event ue_ver_object(false)
//		elseif	UPPER(is_button) = 'NUEVO'  THEN
//			event ue_ver_default()
//			 event ue_settabtext ('Principal')
//			//uo_powerdock.of_setdocumenttext( iuo_tab ,'Consultar / '+is_entidad)
//			//dw_1.enabled= false
//		end if	
//		dw_1.reset()
//		iuo_grillamain.event dynamic ue_activa_opc(false)  
//		iuo_grillamain.event dynamic ue_bloquear_refrescar(false) 
		//	iuo_tab.event dynamic ue_enabled_object(true)
		//	case 'SALIR'
		//		uo_powerdock.of_closedocument(uo_powerdock.of_getactiveobject( ))
END CHOOSE
end event

type dw_1 from u_cst_manto_main`dw_1 within u_cst_noconforme_msj
boolean visible = true
integer y = 108
integer width = 3758
integer height = 1992
string dataobject = "d_msj_noconforme_free"
end type

type uo_1 from u_cst_manto_main`uo_1 within u_cst_noconforme_msj
end type

